as_ai_groups pushBack _this;

//FFIS ai交火系统
{
	_x call ss_FFIS_AddUnit;
}forEach units _this;
//与玩家交火，则从as_ai_groups移除
_this spawn{
	while{true} do{
		sleep 30;
		
		if(isNull _this || {count units _this == 0})exitWith{};
		
		private _leader = leader _this;
		private _player = [_leader, 50] call fn_getPlayerAttack;
		if(!isNull _player) exitWith
		{
			if(Param_Debug == 1)then{systemChat "squadAI: 退出逻辑！"};
			_this setVariable ['as_group_fire', true];
		};
		_player = [_leader, 300] call fn_getPlayerAttack;
		if(!isNull _player) exitWith
		{
			if(Param_Debug == 1)then{systemChat "squadAI: 寻找掩体！"};
			[_this, _player] call fn_findCover; 
			_this setVariable ['as_group_fire', true];
		};
		_player = [_leader, 500] call fn_getPlayerAttack;
		if(!isNull _player) exitWith
		{
			if(Param_Debug == 1)then{systemChat "squadAI: 进驻建筑！"};
			[_this, 150] call fn_findBuildingCover; 
			_this setVariable ['as_group_fire', true];
		};
		
		
	};
	
	as_ai_groups deleteAt (as_ai_groups find _this);
};

private _num_min = ceil((count units _this) * Param_EnemyEscape);

waitUntil
{
	sleep 10;
	(count units _this) < _num_min
};

//从ai控制组移除
as_ai_groups deleteAt (as_ai_groups find _this);

if((count units _this) == 0)exitWith{};

if(Param_Debug == 1)then
{
	systemChat "一队ai正在溃逃";
	_this setGroupIconParams [[0,0,0,1],"溃散",1,true];
};



private _unit = leader _this;
private _player = [_unit, 1200] call fn_getPlayerAttack;

if!(isNull _player) then
{
	//如果玩家太近直接投降
	if(_unit distanceSqr _player < 10000) then
	{
		{
			_x spawn fn_captiveAI;
		}forEach units _this;
	}
	else
	{
		//反向
		private _pos_back = (position _unit) getPos [2000, (_unit getDir _player) + 180];
		[_this, _pos_back] call fn_addWaypoint;

		//_this setBehaviour "CARELESS";
		_this setFormation "LINE";
		_this setSpeedMode "FULL";
		
		
		if(Param_Debug == 1) then
		{
			private _marker = createMarker [format["marker_wp_%1", as_waypoint_cur], _pos_back];
			_marker setMarkerShape "ICON";
			_marker setMarkerColor "ColorGreen";
			_marker setMarkerType "mil_arrow";
			_marker setMarkerText "撤退";
			as_waypoint_cur = as_waypoint_cur + 1;
		};
	};
};

//如果没有发现玩家在附近
_this setBehaviour "Stealth";